package com.ruoyi.car.service.impl;

import java.util.HashMap;
import java.util.List;

import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.car.mapper.CarGarageMapper;
import com.ruoyi.car.domain.CarGarage;
import com.ruoyi.car.service.ICarGarageService;

/**
 * 车库Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-02
 */
@Service
public class CarGarageServiceImpl implements ICarGarageService 
{
    @Autowired
    private CarGarageMapper carGarageMapper;

    /**
     * 查询车库
     * 
     * @param garageId 车库主键
     * @return 车库
     */
    @Override
    public CarGarage selectCarGarageByGarageId(Long garageId)
    {
        return carGarageMapper.selectCarGarageByGarageId(garageId);
    }

    /**
     * 查询车库列表
     * 
     * @param carGarage 车库
     * @return 车库
     */
    @Override
    public List<CarGarage> selectCarGarageList(CarGarage carGarage)
    {
        return carGarageMapper.selectCarGarageList(carGarage);
    }

    /**
     * 新增车库
     * 
     * @param carGarage 车库
     * @return 结果
     */
    @Override
    public int insertCarGarage(CarGarage carGarage)
    {
        carGarage.setCreateTime(DateUtils.getNowDate());
        return carGarageMapper.insertCarGarage(carGarage);
    }

    @Override
    public boolean editCarGarageNumber(long garageId) {
        CarGarage carGarage =selectCarGarageByGarageId(garageId);
        carGarage.setGarageNumber(carGarage.getGarageNumber() -1);
        if (0==carGarage.getGarageNumber()) {
            carGarage.setGarageStatus("1");
        }
        if (0>carGarage.getGarageNumber()) {
            throw new BaseException("车库车位不足");
        }
        updateCarGarage(carGarage);
        return true;
    }

    @Override
    public boolean reduceCarGarageNumber(long garageId) {
        CarGarage carGarage =selectCarGarageByGarageId(garageId);

        if (0==carGarage.getGarageNumber())
            carGarage.setGarageStatus("0");
        carGarage.setGarageNumber(carGarage.getGarageNumber() + 1);
        updateCarGarage(carGarage);
        return true;
    }

    /**
     * 修改车库
     * 
     * @param carGarage 车库
     * @return 结果
     */
    @Override
    public int updateCarGarage(CarGarage carGarage)
    {
        carGarage.setUpdateTime(DateUtils.getNowDate());
        return carGarageMapper.updateCarGarage(carGarage);
    }

    /**
     * 批量删除车库
     * 
     * @param garageIds 需要删除的车库主键
     * @return 结果
     */
    @Override
    public int deleteCarGarageByGarageIds(Long[] garageIds)
    {
        return carGarageMapper.deleteCarGarageByGarageIds(garageIds);
    }

    /**
     * 删除车库信息
     * 
     * @param garageId 车库主键
     * @return 结果
     */
    @Override
    public int deleteCarGarageByGarageId(Long garageId)
    {
        return carGarageMapper.deleteCarGarageByGarageId(garageId);
    }
}
